package com.ljm.pass.util;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

/**
 * 生成密码工具类
 *
 */
@Component
@ConditionalOnProperty(name = "shiro.credentialsMatcher.matcherName",matchIfMissing =true )
public class PasswordHelper {
    /**
     * 加密方式
     */
    //@Value("${shiro.credentialsMatcher.matcherName}")
    private String algorithmName = "MD5";
    /**
     * 加密次数
     */
    //@Value("${shiro.credentialsMatcher.iterations}")
    private int hashIteration = 5;

    /**
     * 加密密码
     *
     * @param loginPwd
     *            明文密码
     * @param salt
     * @return
     */
    public String getPwd(String loginPwd, String salt) {
        return new SimpleHash(algorithmName, loginPwd, ByteSource.Util.bytes(salt), hashIteration).toHex();
    }
}
